home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / Slide Show < prev    next >
Encoding:
Text File  |  1999-03-04  |  5.6 KB  |  251 lines  |  [TEXT/ToyS]

  1. -- Properties
  2. property kasPrefName : "Slide Show V1.1"
  3. property kasPause : 5 -- Time between slides
  4.  
  5. -- Globals
  6. global gasInfoWind -- Info window
  7. global gasInfoPos -- Position of info window
  8.  
  9. global gasFoldersToDo -- The folders left to process
  10. global gasShown -- Number gone!
  11. global gasChecked -- Number checked!
  12.  
  13. global gasDispIdx
  14. global gasDispCnt
  15. global gasDispBox
  16. global gasDisplays
  17. global gasLastObjs
  18.  
  19.  
  20. on run
  21.     pfLoad()
  22.     open gasLastObjs
  23. end run
  24.  
  25.  
  26. on open fsObjs
  27.     -- Load prefs, show window
  28.     pfLoad()
  29.     set gasLastObjs to fsObjs
  30.     pfSave()
  31.     
  32.     -- Set up prefix
  33.     set gasShown to 0
  34.     set gasChecked to 0
  35.     set gasShowWind to 0
  36.     
  37.     set displays to the display information
  38.     set gasDispIdx to 1
  39.     set gasDispCnt to the number of items of displays
  40.     set gasDispBox to {}
  41.     set gasDisplays to {}
  42.     repeat with dsp in displays
  43.         set box to the monitor box of dsp
  44.         set wDims to {(item 3 of box) - (item 1 of box), (item 4 of box) - (item 2 of box)}
  45.         
  46.         set dWin to ¬
  47.             display drawing titled ("Akua Sweets - " & (item 1 of box) & ":" & (item 2 of box)) ¬
  48.                 located at {item 1 of box, item 2 of box} ¬
  49.                 with dimensions wDims
  50.         
  51.         set wBox to {0, 0} & wDims
  52.         set gasDispBox to gasDispBox & {wBox}
  53.         
  54.         -- Back drop
  55.         draw a box into dWin ¬
  56.             inside of wBox ¬
  57.             filling it with the pen
  58.         
  59.         set gasDisplays to gasDisplays & {dWin}
  60.     end repeat
  61.     
  62.     set gasInfoWind to display info titled kasPrefName ¬
  63.         located at gasInfoPos ¬
  64.         message "Scanning…"
  65.     
  66.     -- Do files
  67.     set gasFoldersToDo to {}
  68.     
  69.     repeat with fsObj in fsObjs
  70.         set myInfo to (basic info for fsObj)
  71.         
  72.         if (system type of myInfo is "fold") then
  73.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  74.         else
  75.             DoOne(fsObj)
  76.         end if
  77.     end repeat
  78.     
  79.     -- Do folders
  80.     repeat while gasFoldersToDo is not {}
  81.         -- Pop one off the end
  82.         set n to the number of items of gasFoldersToDo
  83.         set fsObj to item n of gasFoldersToDo
  84.         
  85.         if (n > 1) then
  86.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  87.         else
  88.             set gasFoldersToDo to {}
  89.         end if
  90.         
  91.         display info gasInfoWind ¬
  92.             message ("Folders to go: " & n) ¬
  93.             at line 6 ¬
  94.             using color (15 * 32)
  95.         
  96.         -- Process it
  97.         GoDeep(fsObj)
  98.     end repeat
  99.     
  100.     display info gasInfoWind message "DONE!"
  101.     
  102.     pause for 5 with seconds timing -- Let screen wait...
  103.     
  104.     set gasInfoPos to screen location of ¬
  105.         (display info gasInfoWind with disposal)
  106.     
  107.     repeat with win in gasDisplays
  108.         display drawing win with disposal
  109.     end repeat
  110.     
  111.     pfSave() -- Save window location
  112. end open
  113.  
  114.  
  115. on DoOne(fsObj)
  116.     set imageType to the image type in fsObj
  117.     set fname to (catalog name of (basic info for fsObj))
  118.     
  119.     display info gasInfoWind ¬
  120.         message fname ¬
  121.         at line 2
  122.     
  123.     if (imageType is not "") then
  124.         display info gasInfoWind ¬
  125.             message imageType ¬
  126.             at line 3
  127.         -- Get picture
  128.         set imagePic to the image from fsObj
  129.         -- Get its bounds
  130.         set pBox to picture bounds of (the picture info for imagePic)
  131.         -- Center it
  132.         set drawInto to PlaceInCenter(pBox, item gasDispIdx of gasDispBox)
  133.         -- Show new image
  134.         draw a box into (item gasDispIdx of gasDisplays) ¬
  135.             inside of (item gasDispIdx of gasDispBox) ¬
  136.             filling it with the pen ¬
  137.             without recording
  138.         draw a picture into (item gasDispIdx of gasDisplays) ¬
  139.             inside of drawInto ¬
  140.             using data imagePic ¬
  141.             without recording
  142.         -- Go to next display
  143.         set imagePic to 0
  144.         set gasDispIdx to gasDispIdx + 1
  145.         if (gasDispIdx > gasDispCnt) then set gasDispIdx to 1
  146.         -- Wait a sec or two
  147.         pause for kasPause with seconds timing
  148.         
  149.         if (shift key down of (input state)) then ¬
  150.             display dialog "Continue?" default button 1
  151.     else
  152.         display info gasInfoWind ¬
  153.             message ¬
  154.             "Unknown" at line 3
  155.     end if
  156. end DoOne
  157.  
  158.  
  159. on GoDeep(foldObj)
  160.     display info gasInfoWind ¬
  161.         message "Path: " & (foldObj as string)
  162.     
  163.     set daddy to foldObj as string
  164.     
  165.     -- Do kinds that match    
  166.     set myItems to the entries in foldObj ¬
  167.         whose kinds are a file
  168.     
  169.     set n to the number of items in myItems
  170.     
  171.     display info gasInfoWind ¬
  172.         message "Scanning " & n & " files" at line 5
  173.     
  174.     repeat with i from n to 1 by -1
  175.         set x to random number from 1 to i
  176.         set myItem to item x of myItems
  177.         if (x is 1) then
  178.             if (i is 1) then
  179.                 set myItems to {}
  180.             else
  181.                 set myItems to items 2 through -1 of myItems
  182.             end if
  183.         else if (x is i) then
  184.             set myItems to items 1 through -2 of myItems
  185.         else
  186.             set myItems to (items 1 through (x - 1) of myItems) & (items (x + 1) through -1 of myItems)
  187.         end if
  188.         DoOne((daddy & myItem) as alias)
  189.     end repeat
  190.     
  191.     -- Do folders
  192.     display info gasInfoWind ¬
  193.         message "Scanning subfolders" at line 5
  194.     
  195.     set myItems to the entries in foldObj ¬
  196.         whose kinds are a folder
  197.     
  198.     repeat with myItem in myItems
  199.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  200.     end repeat
  201.     
  202.     -- Done
  203.     display info gasInfoWind ¬
  204.         message "…" at line 5
  205. end GoDeep
  206.  
  207.  
  208. on PlaceInCenter(src, dst)
  209.     -- Place src in dst w/ scaling
  210.     set sW to (item 3 of src) - (item 1 of src)
  211.     set sH to (item 4 of src) - (item 2 of src)
  212.     set dW to (item 3 of dst) - (item 1 of dst)
  213.     set dH to (item 4 of dst) - (item 2 of dst)
  214.     
  215.     set r to dW / sW
  216.     set rH to dH / sH -- ratios
  217.     
  218.     if (rH < r) then set r to rH
  219.     
  220.     -- Round to a .25 ratio if > 1
  221.     if (r > 1) then ¬
  222.         set r to 0.25 * (round (r * 4))
  223.     
  224.     -- Scale the src
  225.     set sW to round (sW * r)
  226.     set sH to round (sH * r)
  227.     set mW to round ((dW - sW) / 2)
  228.     set mH to round ((dH - sH) / 2)
  229.     
  230.     -- Center it
  231.     return {mW, mH, mW + sW, mH + sH}
  232. end PlaceInCenter
  233.  
  234.  
  235. on pfLoad()
  236.     try
  237.         set ourPrefs to (load preference named kasPrefName)
  238.     on error
  239.         set ourPrefs to {{8, 48}, {8, 96}, {}}
  240.     end try
  241.     
  242.     set gasInfoPos to item 1 of ourPrefs
  243.     set gasShowLoc to item 2 of ourPrefs
  244.     set gasLastObjs to item 3 of ourPrefs
  245. end pfLoad
  246.  
  247.  
  248. on pfSave()
  249.     save preference {gasInfoPos, {-1, -1}, gasLastObjs} named kasPrefName
  250. end pfSave
  251.